using System.Windows.Forms;
using NUnit.Framework;
using ShadeTree.Binding.Settings;

namespace ShadeTree.Binding.Tests.Settings
{
    [TestFixture]
    public class StoreAndRememberTester
    {
        #region Setup/Teardown

        [SetUp]
        public void SetUp()
        {
            LastChosenValues.Clear();
        }

        #endregion

        [Test]
        public void ReturnNullGracefullyIfTheControlIsNotStored()
        {
            var control = new Control();
            control.Name = "control1";

            var specialControl = new SpecialControl();
            specialControl.Controls.Add(control);

            LastChosenValues.Retrieve(control).ShouldBeNull();
        }

        [Test]
        public void StoreAndRememberAnObjectByControlFromLastChosenValues()
        {
            var control = new Control();
            control.Name = "control1";

            var specialControl = new SpecialControl();
            specialControl.Controls.Add(control);

            var control2 = new Control();
            control2.Name = "control1";
            var specialControl2 = new SpecialControl2();
            specialControl2.Controls.Add(control2);

            LastChosenValues.Store(control, "blue");
            LastChosenValues.Store(control2, "red");

            LastChosenValues.Retrieve(control).ShouldEqual("blue");
            LastChosenValues.Retrieve(control2).ShouldEqual("red");
        }
    }

    public class SpecialControl : Control
    {
    }

    public class SpecialControl2 : Control
    {
    }
}